{config_load file=ua.conf section="head"}
<script type="text/javascript"
	src="themes/{$theme}/js/jquery.validate.js"></script>

{literal}

<style type="text/css">
label {
	width: 10em;
	float: left;
}

label.error {
	float: none;
	color: red;
	padding-left: .5em;
	vertical-align: top;
}

p {
	clear: both;
}

.submit {
	margin-left: 12em;
}

em {
	font-weight: bold;
	padding-right: 1em;
	vertical-align: top;
}
</style>
<script LANGUAGE="JavaScript">

var r;
var digit = new Array("0","1","2","3","4","5","6","7","8","9");
var halp = new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","Y","Z");
var lalp = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","y","z");
pasw = new String();

function RandomPass()
{

   pasw = "";

 for (var i= 0; i<8; i++)
    {
  r = Math.random();
if ( (r - 1.0/3.0) < 0.0)
  {
   r = Math.floor(Math.random() * 9);
pasw += digit[r];
  }
    else if ( (r - 2.0/3.0) < 0.0)
      {
  r = Math.floor(Math.random() * 24);
pasw += halp[r];
  }
else
 {
   r = Math.floor(Math.random() * 24);
pasw += lalp[r];
          }
         }
            document.getElementById('password').value = pasw;
  }
  function transliter(id) {

 var field = document.getElementById(id);
 var from = field.value.toLowerCase();

 var rusChars = new Array('і','ї','є','а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','х','ч','ц','ш','щ','э','ю','\я','ы','ъ','ь', ' ', '\'', '\"', '\#', '\$', '\%', '\&', '\*', '\,', '\:', '\;', '\<', '\>', '\?', '\[', '\]', '\^', '\{', '\}', '\|', '\!', '\@', '\(', '\)', '\-', '\=', '\+', '\/', '\\');
 var transChars = new Array('i','i','e','a','b','v','g','d','e','jo','zh','z','i','j','k','l','m','n','o','p','r','s','t','u','f','h','ch','c','sh','csh','e','ju','ja','y','_', '_', '_', '_', '_', '_', '_', '_', '_', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '_', '_', '_', '_', '_');
 var to = '';
 var len = from.length;
 var rlen = rusChars.length;
 var character, isRus;
 
 for(var i = 0; i < 7; i++)
  {
  var character = from.charAt(i,1);
  var foundIndex = rusChars.indexOf(character);
  to += (foundIndex != -1) ? transChars[foundIndex] : character;
  }
  document.getElementById('login').value = to;

 }



    $(document).ready(function(){
        $("#new").validate(
    {

        rules: {
            "options[tariff]": "required",
            StreetID: "required",
            Apartn: "number",
            Entrance:"number",
            Buildingn:{required:true},
            Floor:"number",
            "options[cash]":"number",
            "options[ip]": "required",
            "options[name]":{required:true, minlength:3},
            "options[login]":{required:true, minlength:3,maxlength:10},
            "options[password]":{required:true, minlength:6},
 
              },
       submitHandler: function(form) {

			$('#new').ajaxSubmit({succes:$( this ).ajaxComplete(function(){page( 'user' ,document.getElementById('login').value)})}) ;
                        return false;
			
    }

    });
        
    
                                                                                       
          });
function iflogin(login)
{
    $.ajax({
    type: "POST",
    data: "user=" + login ,
    url: "index.php?type=iflogin",
    success: function(html){
if(html == login)
{
    $("#login").css("border","2px solid red");
}
else
{
$("#login").css("border","2px solid green");
}
    }
    });
}
          function freeip(ip)
          {

$.get("index.php", { type: "freeip", ip: ip },
   function(data){
        //alert("Data Loaded: " + data);
    $('#ip').attr("value",data);
           });              
          
                    
          }

            </script>
{/literal}
<div id="new_user">
<h1 align="center">Створення нового абонента</h1>
<form id="new" method="POST" action="index.php?type=new_user">
<table>
	<tbody>
		<tr>
			<td>Ім'я:</td>
			<td><input id="name" type="text" name="options[name]"  value=""> </td>
		</tr>
		<tr>
			<td>Логін:</td>
			<td><input id="login" type="text" name="options[login]" onBlur="iflogin(this.value)" value=""> -
			a-zA-z_-.<br>
			<a onclick='transliter("name")' href="javascript:void(0)">Згенерувати</a></td>
		</tr>
		<tr>
			<td>Пароль:</td>
			<td><input id="password" type="text" name="options[password]"
				value=""> - Не менше 6 символів<br>
			<a onClick="RandomPass()" href="javascript:void(0)">Згенерувати</a></td>
		</tr>
		<tr>
			<td>Адреса:</td>
			<td align="center"><select id="streetid" name="StreetID">
				<option value="">Оберіть вулицю</option>
				{section name=i loop = $street}
				<option value="{$street[i].ID}">{$street[i].Name}</option>
				{/section}
			</select> <br>
			<br>
			Буд. <input type="text" size="2" name="Buildingn" id="Buildingn"
				value=""> Під. <input type="text" size="2" name="Entrance"
				id="Entrance" value=""> Пов. <input type="text" size="2"
				name="Floor" id="Floor" value=""> Кв. <input type="text" size="2"
				name="Apartn" id="Apartn" value=""></td>
		</tr>
		<tr>
			<td>Тариф:</td>
			<td><select id="tariff" name="options[tariff]">
				<option value="">Оберіть тариф</option>
				{section name=i loop = $tariffs}
				<option>{$tariffs[i].name}</option>
				{/section}
			</select> <input type="hidden" name="tariff_type" value="now"></td>
		</tr>
		<tr>
			<td>IP адреса:</td>
			<td><input id="ip" type="text" name="options[ip]" value=""> <br>
			<select onchange="freeip(this.value)">
				<option>Обрати вільний</option>
				{section name=i loop=$ips}
				<option value="{$ips[i].Address}">{$ips[i].Name}({$ips[i].Address})</option>
				{/section}
			</select></td>
		</tr>
		<tr>
			<td>Пошта:</td>
			<td><input class="email" type="text" name="options[email]" value=""></td>
		</tr>
		<tr>
			<td>Телефон:</td>
			<td><input type="text" name="options[phone]" value=""></td>
		</tr>
		<tr>
			<td>Завжди онлайн:</td>
			<td><input type="checkbox" name="options[aonline]" value="1"> -
			Оберіть для активації</td>
		</tr>
		<tr>
			<td>Вимкнений:</td>
			<td><input type="checkbox" name="options[down]" value="1"> - Оберіть
			для активації</td>
		</tr>
		<tr>
			<td>Заморожений:</td>
			<td><input type="checkbox" name="options[passive]" value="1"> -
			Оберіть для активації</td>
		</tr>
		<tr>
			<td>Відключення детальної статистики:</td>
			<td><input type="checkbox" CHECKED name="options[disabledetailstat]"
				value="1"> - Оберіть для активації</td>
		</tr>
		<tr>
			<td>Баланс:</td>
			<td><input id="balance" type="text" size="3" name="options[cash]"
				value="0"> <input type="hidden" name="cash_type" value="add"> грн.</td>
		</tr>
		<tr>
			<td>Коментар:</td>
			<td><textarea name="options[note]"></textarea></td>
		</tr>

		<tr>
			<td></td>
			<td align="right"><input type="reset" value="Очистити"><input
				type="hidden" name="action" value="AddUser"> <input name="submit"
				type="submit" OnClick="{literal}if(!confirm('{/literal}{#save#}{literal}')) { return false;}{/literal}" value="Створити"></td>
		</tr>
	</tbody>
</table>
</form>
</div>